package com.deke.system.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.deke.entity.AclRole;
import com.deke.security.annotation.RequiresPermission;
import com.deke.system.service.AclRoleService;
import com.deke.system.vo.FenRoleVo;
import com.deke.system.vo.RoleVo;
import com.deke.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author ：Username 刘亦辰（59372312@qq.com）
 * @date ：Created in 2022/12/4 14:08
 * @description：
 * @modified By：
 * @version:
 **/

@RestController
@RequestMapping("/system/role/")
@Api(tags = "角色接口类")
public class AclRoleController {

    @Autowired
    private AclRoleService roleService;
    /**
     * @create by: Username 刘亦辰 
     * @description: 角色分页查询 
     * @create time: 2022/12/4 14:09
     * @param null
     * @return :  
     **/
    @PostMapping("/findRoleByPage/{current}/{pageSize}")
    @ApiOperation(value = "角色模糊查询")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "当且页码数",name = "current"),
            @ApiImplicitParam(value = "每页的行数",name = "pageSize"),
            @ApiImplicitParam(value = "前端实体类",name = "roleVo")
    })
    public Result<IPage<AclRole>> findRoleByPage(@PathVariable Integer current, @PathVariable Integer pageSize, @RequestBody RoleVo roleVo){
        return roleService.queryByConditionPage(current,pageSize,roleVo);
    }

    /**
     * @create by: Username 刘亦辰 
     * @description: 角色添加 
     * @create time: 2022/12/4 14:41
     * @param null
     * @return :  
     **/
    @RequiresPermission(value = "role:add")
    @PostMapping("addRole")
    @ApiOperation(value = "添加角色")
    @ApiImplicitParam(value = "前端实体类",name = "roleVo")
    public Result<AclRole> addRole(@RequestBody RoleVo roleVo){
       return roleService.addRole(roleVo);
    }

    /**
     * @create by: Username 刘亦辰 
     * @description:  修改用户角色
     * @create time: 2022/12/4 14:56
     * @param null
     * @return :  
     **/
    @GetMapping("/findRoleByUserId/{id}")
    @ApiOperation(value = "根据用户id查角色")
    @ApiImplicitParam(value = "用户ID",name = "id")
    public Result findRoleByUserId(@PathVariable String id){
        return  roleService.findRoleByUserId(id);
    }

    /**
     * @create by: Username 刘亦辰 
     * @description:  
     * @create time: 2022/12/4 21:57
     * @param null
     * @return :  
     **/
    @PostMapping("/findRoleByRoleName/{roleCurrentPage}/{rolePageSize}")
    @ApiOperation("根据角色名称查角色")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "当前页码数",name = "roleCurrentPage"),
            @ApiImplicitParam(value = "每页的行数",name = "rolePageSize"),
            @ApiImplicitParam(value = "前端实体类",name = "roleVo")
    })
    public Result<IPage<AclRole>> findRoleByRoleName(@PathVariable Integer roleCurrentPage, @PathVariable Integer rolePageSize, @RequestBody RoleVo roleVo ){
        return roleService.queryByConditionPage(roleCurrentPage,rolePageSize,roleVo);
    }

    /**
     * @create by: Username 刘亦辰 
     * @description: 分配角色 
     * @create time: 2022/12/5 18:01
     * @param null
     * @return :  
     **/
    @PostMapping("fenUserRole")
    @ApiOperation(value = "确认分配角色")
    @ApiImplicitParam(value = "前端实体类",name = "fenRoleVo")
    public Result fenUserRole(@RequestBody FenRoleVo fenRoleVo){
        return roleService.fenUserRole(fenRoleVo);
    }
    
    
    /**
     * @create by: Username 刘亦辰 
     * @description: 角色管理  编辑角色 
     * @create time: 2022/12/5 23:22
     * @param null 
     * @return :  
     **/
    @RequiresPermission(value = "role:update")
    @PostMapping("addOrUpdateRole")
    @ApiOperation(value = "编辑角色的信息")
    @ApiImplicitParam(value = "实体类",name = "aclRole")
    public Result addOrUpdateRole(@RequestBody AclRole aclRole){
        return roleService.addOrUpdateRole(aclRole);
    }

    /**
     * @create by: Username 刘亦辰 
     * @description: 角色管理   修改状态 
     * @create time: 2022/12/5 23:30
     * @param null
     * @return :  
     **/
    @RequiresPermission(value = "role:update")
    @PostMapping("/updateRoleStatusByid/{id}/{deleted}")
    @ApiOperation(value = "通过角色id修改角色的状态")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "角色ID",name = "id"),
            @ApiImplicitParam(value = "角色的状态",name = "deleted")
    })
    public Result updateRoleStatusByid(@PathVariable String id, @PathVariable String deleted){
        return roleService.updateRoleStatusByid(id,deleted);
    }

    /**
     * @create by: Username 刘亦辰 
     * @description: 角色管理   用户删除 
     * @create time: 2022/12/5 23:46
     * @param null
     * @return :  
     **/
    @RequiresPermission(value = "role:remove")
    @DeleteMapping("/deleteRoleById/{roleId}")
    @ApiOperation(value = "通过角色id删除角色")
    @ApiImplicitParam(value = "角色ID",name = "roleId")
    public Result deleteRoleById(@PathVariable String roleId){
        System.out.println(roleId);
        return roleService.deleteRoleById(roleId);
    }
    

}